<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:s="http://jboss.com/products/seam/taglib"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:rich="http://richfaces.org/rich"
    xmlns:a="http://richfaces.org/a4j"
    template="layout/template.xhtml">

<ui:define name="body">

	<s:div rendered="#{VendaBean.erroGlobal}">
		<h:message />
	</s:div>

    <h:form id="vendaFinanceiroForm">
    

				<rich:panel id="painelEntrada2">
						<s:div  rendered="#{not empty VendaBean.lotes}">
						 <h3>
						 	<h:outputText value="Total lotes: " />
							<h:outputText value="R$ #{VendaBean.valorTotalLotes()}" />
						 </h3>
						 <h3>
						 	<h:outputText value="Desconto: R$ " />
							<h:inputText id="idVlDesconto" value="#{VendaBean.venda.valorDesconto}" >
								<a:support event="onchange" reRender="vlTotalVenda" />
							</h:inputText>
						 </h3>
						 <h3>
						 	<h:outputText value="Total da Venda: " />
							<h:outputText id="vlTotalVenda"  value="R$ #{VendaBean.calculaValorVenda()}" />
						 </h3>
						</s:div>
				</rich:panel>
				<br/>
				<rich:panel id="painelEntrada">
				<f:facet name="header">Entrada</f:facet>

					<table>
						<tr>
							<td>
					            <s:decorate id="valorEntradaFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Valor Entrada</ui:define>
					                <h:inputText id="valorEntradaId" value="#{VendaBean.venda.valorEntrada}"  >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
							</td>
							<td>
					            <s:decorate id="formaPgtoEntradaFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Forma Pgto</ui:define>
					                <h:selectOneMenu id="formaPgtoEntradaId" value="#{VendaBean.venda.formaPgtoEntrada}"  >
				                     <s:selectItems value="#{formasPgto}"
				                                    var="_formaPgto"
				                                    label="#{_formaPgto}"
				                                    noSelectionLabel="Selecione" >
				                                    </s:selectItems>
				                                    <a:support event="onchange" reRender="painelEntrada" />
	                                    <s:convertEnum/>  
					                	<s:validate />
					                </h:selectOneMenu>
					            </s:decorate>
							</td>
						</tr>
						<tr>

							<td>
						            <s:decorate id="numBancoChqEntradaFieldId" template="/layout/edit.xhtml" rendered="#{VendaBean.venda.formaPgtoEntrada eq 'CHEQUE'}" >
						                <ui:define name="label">Banco</ui:define>
						                <h:inputText id="numBancoChqEntradaId" value="#{VendaBean.venda.numBancoChqEntrada}" size="4" maxlength="3" >
						                	<s:validate />
						                </h:inputText>
						            </s:decorate>
							</td>
							<td>
						            <s:decorate id="numAgenciaChqEntradaFieldId" template="/layout/edit.xhtml" rendered="#{VendaBean.venda.formaPgtoEntrada eq 'CHEQUE'}" >
						                <ui:define name="label">Agencia</ui:define>
						                <h:inputText id="numAgenciaChqEntradaId" value="#{VendaBean.venda.numAgenciaChqEntrada}"  size="8" maxlength="6" >
						                	<s:validate />
						                </h:inputText>
						            </s:decorate>
							</td>
							<td>
						            <s:decorate id="numContaChqEntradaFieldId" template="/layout/edit.xhtml" rendered="#{VendaBean.venda.formaPgtoEntrada eq 'CHEQUE'}" >
						                <ui:define name="label">Conta</ui:define>
						                <h:inputText id="numContaChqEntradaId" value="#{VendaBean.venda.numContaChqEntrada}" size="12" maxlength="10" >
						                	<s:validate />
						                </h:inputText>
						            </s:decorate>
							</td>
							<td>
						            <s:decorate id="numChqEntradaFieldId" template="/layout/edit.xhtml" rendered="#{VendaBean.venda.formaPgtoEntrada eq 'CHEQUE'}" >
						                <ui:define name="label">Cheque</ui:define>
						                <h:inputText id="numChqEntradaId" value="#{VendaBean.venda.numChqEntrada}"  >
						                	<s:validate />
						                </h:inputText>
						            </s:decorate>
							</td>
						</tr>
						<tr>
							<td>
						            <s:decorate id="chqEntradaTerceiroFieldId" template="/layout/edit.xhtml" rendered="#{VendaBean.venda.formaPgtoEntrada eq 'CHEQUE'}" >
						                <ui:define name="label">Cheque de Terceiro?</ui:define>
						                <h:selectOneMenu id="chqEntradaTerceiroEntradaId" value="#{VendaBean.venda.chqEntradaTerceiro}"  >
					                     <s:selectItems value="#{simNaoList}"
					                                    var="_simNao"
					                                    label="#{_simNao}"
					                                    noSelectionLabel="Selecione" >
					                                    </s:selectItems>
					                                    <a:support event="onchange" reRender="painelEntrada" />
		                                    <s:convertEnum/>  
						                	<s:validate />
						                </h:selectOneMenu>
						            </s:decorate>
							</td>
							<td colspan="2">
						            <s:decorate id="nomeTerceiroChqEntradaFieldId" template="/layout/edit.xhtml" rendered="#{VendaBean.venda.formaPgtoEntrada eq 'CHEQUE' and VendaBean.venda.chqEntradaTerceiro eq 'SIM'}" >
						                <ui:define name="label">Nome terceiro</ui:define>
						                <h:inputText id="nomeTerceiroChqEntradaId" value="#{VendaBean.venda.nomeTerceiroChqEntrada}" size="60" maxlength="50" >
						                	<s:validate />
						                </h:inputText>
						            </s:decorate>
							</td>
							<td>
						            <s:decorate id="cpfTerceiroChqEntradaFieldId" template="/layout/edit.xhtml" rendered="#{VendaBean.venda.formaPgtoEntrada eq 'CHEQUE' and VendaBean.venda.chqEntradaTerceiro eq 'SIM'}" >
						                <ui:define name="label">CPF terceiro</ui:define>
						                <h:inputText id="cpfTerceiroChqEntradaId" value="#{VendaBean.venda.cpfTerceiroChqEntrada}" size="15" maxlength="14" >
						                	<s:validate />
						                </h:inputText>
						            </s:decorate>
							</td>
						</tr>
					</table>
				
					
				</rich:panel>
				
				<br/><br/>
				
				<rich:panel id="painelFinanCEF">
				<f:facet name="header">Financiamento Caixa Economica </f:facet>
				<img src="img/cef.jpg" width="30" height="15" />
					<table>
						<tr>
							<td>
					            <s:decorate id="valorFinanCEFFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Valor Financiado</ui:define>
					                <h:inputText id="valorFinanCEFId" value="#{VendaBean.venda.valorFinanCEF}"  >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
							</td>
							<td>
					            <s:decorate id="dataPrimeiraParcelaFinanCEFFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Data 1a Parcela</ui:define>
					                <rich:calendar id="dataPrimeiraParcelaFinanCEFId" value="#{VendaBean.venda.dataPrimeiraParcelaFinanCEF}" datePattern="dd/MM/yyyy" >
					                	<s:validate/>
					                </rich:calendar>
					            </s:decorate>
							</td>
							<td>
					            <s:decorate id="numTotalParcelaFinanCEFFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Quantidade Parcelas</ui:define>
					                <h:inputText id="numTotalParcelaFinanCEFId" value="#{VendaBean.venda.numTotalParcelaFinanCEF}" size="5" maxlength="4" >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
							</td>
							<td>
					            <s:decorate id="valorParcelaFinanCEFFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Valor Parcela</ui:define>
					                <h:inputText id="valorParcelaFinanCEFId" value="#{VendaBean.venda.valorParcelaFinanCEF}" >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
							</td>
						</tr>
					</table>
				</rich:panel>

				<br/><br/>

				
				<rich:panel id="painelFinanProp">
				<f:facet name="header">Financiamento Proprio</f:facet>
				<s:div rendered="#{!VendaBean.erroGlobal}" >
					<h:messages />
				</s:div>
					<table>
						<tr>
							<td>
					            <s:decorate id="valorChqFinanPropFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Valor cheque</ui:define>
					                <h:inputText id="valorChqFinanPropId" value="#{VendaBean.valorChqFinanProp}"  >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
					        </td>
							<td>
					            <s:decorate id="dataVencimentoChqFinanPropFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Data</ui:define>
					                <rich:calendar id="dataVencimentoChqFinanPropId" value="#{VendaBean.dataVencimentoChqFinanProp}" datePattern="dd/MM/yyyy" >
					                	<s:validate />
					                </rich:calendar>
					            </s:decorate>
					        </td>
							<td>
					            <s:decorate id="numBancoChqFinanPropFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Banco</ui:define>
					                <h:inputText id="numBancoChqFinanPropId" value="#{VendaBean.numBancoChqFinanProp}"  >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
					        </td>
							<td>
					            <s:decorate id="numAgenciaChqFinanPropFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Agencia</ui:define>
					                <h:inputText id="numAgenciaChqFinanPropId" value="#{VendaBean.numAgenciaChqFinanProp}"  >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
					        </td>
							<td>
					            <s:decorate id="numContaChqFinanPropFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Conta</ui:define>
					                <h:inputText id="numContaChqFinanPropId" value="#{VendaBean.numContaChqFinanProp}"  >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
					        </td>
							<td>
					            <s:decorate id="numChqFinanPropFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Numero Cheque</ui:define>
					                <h:inputText id="numChqFinanPropId" value="#{VendaBean.numChqFinanProp}"  >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
					        </td>
					    </tr>
					    <tr>
							<td>
					            <s:decorate id="chqTerceiroFinanPropFieldId" template="/layout/edit.xhtml">
					                <ui:define name="label">Cheque Terceiro?</ui:define>
						                <h:selectOneMenu id="chqTerceiroFinanPropId" value="#{VendaBean.chqTerceiroFinanProp}"  >
					                     <s:selectItems value="#{simNaoList}"
					                                    var="_simNao"
					                                    label="#{_simNao}"
					                                    noSelectionLabel="Selecione" >
					                                    </s:selectItems>
					                                    <a:support event="onchange" reRender="painelFinanProp" />
		                                    <s:convertEnum/>  
						                	<s:validate />
						                </h:selectOneMenu>
					            </s:decorate>
					        </td>
							<td colspan="2">
					            <s:decorate id="nomeTerceiroChqFinanPropFieldId" template="/layout/edit.xhtml" rendered="#{VendaBean.chqTerceiroFinanProp eq 'SIM'}">
					                <ui:define name="label">Nome Terceiro</ui:define>
					                <h:inputText id="nomeTerceiroChqFinanPropId" value="#{VendaBean.nomeTerceiroChqFinanProp}"  size="60" maxlength="50" >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
					        </td>
							<td>
					            <s:decorate id="cpfTerceiroChqFinanPropFieldId" template="/layout/edit.xhtml" rendered="#{VendaBean.chqTerceiroFinanProp eq 'SIM'}">
					                <ui:define name="label">CPF Terceiro</ui:define>
					                <h:inputText id="cpfTerceiroChqFinanPropId" value="#{VendaBean.cpfTerceiroChqFinanProp}"  >
					                	<s:validate />
					                </h:inputText>
					            </s:decorate>
					        </td>
					    </tr>
					</table>

					<div style="clear:both"/>

					<br/>

			        <div class="actionButtons">
			            <a:commandButton id="btAddParcelaFinanProp"
			                          value="Adicionar Cheque"
			                         action="#{VendaBean.addParcelaFinanProp()}"
			                         reRender="painelFinanProp"/>
					</div>

					<br/>

			        <div class="results">
			
			            <h:outputText value="Nenhum cheque adicionado. Para adicionar um cheque informe os campos acima e click no botao Adicionar Cheque"
			                       rendered="#{empty VendaBean.parcelasFinanciamentoProprio}"/>
			
			            <rich:dataTable id="parcelasFinanciamentoProprioList" var="_parcelaFinanProp"
			                      value="#{VendaBean.parcelasFinanciamentoProprio}"
			                   rendered="#{not empty VendaBean.parcelasFinanciamentoProprio}" styleClass="center-text">
			                <h:column>
			                    <f:facet name="header">Valor</f:facet>
			                    #{_parcelaFinanProp.valor}
			                </h:column>
			                <h:column>
			                    <f:facet name="header">Data</f:facet>
			                    <h:outputText value="#{_parcelaFinanProp.dataVencimento}" >
			                    	<f:convertDateTime pattern="dd/MM/yyyy"/>
			                    </h:outputText>
			                </h:column>
			                <h:column>
			                    <f:facet name="header">Banco</f:facet>
			                    #{_parcelaFinanProp.numBancoChq}
			                </h:column>
			                <h:column>
			                    <f:facet name="header">Agencia</f:facet>
			                    #{_parcelaFinanProp.numAgenciaChq}
			                </h:column>
			                <h:column>
			                    <f:facet name="header">Conta</f:facet>
			                    #{_parcelaFinanProp.numContaChq}
			                </h:column>
			                <h:column>
			                    <f:facet name="header">Numero Cheque</f:facet>
			                    #{_parcelaFinanProp.numChq}
			                </h:column>
			                <h:column>
			                    <f:facet name="header">Terceiro </f:facet>
			                    #{_parcelaFinanProp.chqTerceiro eq 'SIM' ? _parcelaFinanProp.cpfTerceiro.concat(' ').concat(_parcelaFinanProp.nomeTerceiro)  : _parcelaFinanProp.chqTerceiro}
			                </h:column>
			            </rich:dataTable>
			
			        </div>
					
				</rich:panel>
				
				<div class="actionButtons">
				
		    		<s:button id="btCliente" value="Cliente" view="/vendaCliente.xhtml" rendered="#{conversation.longRunning}" propagation="join" />
		    		<s:button id="btLote" value="Lote" view="/vendaLote.xhtml" propagation="join" />
		            <h:commandButton id="save" value="Finalizar Venda" action="#{VendaBean.novaVenda}"/>
        
				</div>
				
				
    </h:form>

</ui:define>

</ui:composition>
